package view;

import java.awt.Dimension;

import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;

import model.ISPGraph;
import model.SPGraph;

public class TextualView extends AbstractGraphView {
     
	// FIELDS
	private static final long serialVersionUID = -6142940281113041201L;
	
	private JTextArea textPane;
	private JScrollPane jsPane;
	
	// CONSTRUCTERS
	public TextualView(ISPGraph model) {
		super(model);
		createComponents();
		placeComponents();
	}
	
	public TextualView() {
		this(new SPGraph());
	}
	
	// METHODS
	protected void createComponents() {
		this.textPane = new JTextArea(25, 25);
		textPane.setEditable(false);
		this.jsPane = new JScrollPane(this.textPane);
		this.textPane.setText(getModel().toString());
	}
	
	protected void placeComponents() {
		jsPane = new JScrollPane(this.textPane);
		jsPane.setPreferredSize(new Dimension(450, 300));
		jsPane.setBorder(new TitledBorder("Textual View"));
		this.add(jsPane);
	}
	
	public JScrollPane getSP() {
		return this.jsPane;
	}
	
	public JTextArea getTextPane() {
		return this.textPane;
	}
	
	public void updateView() {
		this.textPane.setText(getModel().toString());
	}
	
	public void setModel(ISPGraph model) {
		super.setModel(model);
		updateView();
	}
}
